package com.inossem.warehousestorage_inossem.activity.inventory;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.inossem.loadandrefresh.pullableview.PullableListView;
import com.inossem.utils.listener.NoDoubleClickListener;
import com.inossem.warehousestorage_inossem.R;
import com.inossem.warehousestorage_inossem.activity.base.BaseActivity;
import com.inossem.warehousestorage_inossem.adapter.inventory.InventoryListAdapter;
import com.inossem.warehousestorage_inossem.bean.inventory.InventoryMgrBean;
import com.inossem.warehousestorage_inossem.listener.GsonBeanListener;
import com.inossem.warehousestorage_inossem.request.inventory.InventoryManageRequest;
import com.inossem.warehousestorage_inossem.utils.ActivityUtils;

public class Inventory_ManageActivity extends BaseActivity {

    TextView title;
    private PullableListView list;

    private InventoryListAdapter adapter;

    @Override
    protected void onCreateImpl(Bundle savedInstanceState) {
        setContentView(R.layout.activity_inventory_manage);
        initView(Inventory_ManageActivity.this);
        initData(Inventory_ManageActivity.this);
    }

    @Override
    protected void onResumeImpl() {
        getData(this);
    }

    private void initView(Activity activity) {
        title = (TextView) activity.findViewById(R.id.headerTitle);
        ActivityUtils.initBackAndFunction(activity, R.string.activity_main_title_short, new NoDoubleClickListener() {
            @Override
            public void onNoDoubleClick(View v) {
                finish();
            }
        });
        list = (PullableListView) activity.findViewById(R.id.list);
        list.setPullDownFlag(false);
        list.setPullUpFlag(false);
}

    public PullableListView getList() {
        return list;
    }

    public void setList(PullableListView list) {
        this.list = list;
    }

    private void initData(Activity activity) {
        title.setText(activity.getResources().getString(R.string.activity_inventory_manage_title));
    }

    private void getData(final Activity activity) {
        InventoryManageRequest.request(activity, new GsonBeanListener<InventoryMgrBean>() {
            @Override
            public void onSuccess(InventoryMgrBean bean) {
                adapter = new InventoryListAdapter(activity,bean);
                getList().setAdapter(adapter);
            }
        });
    }

}
